import 'package:city_pickers/city_pickers.dart';
import 'package:city_pickers/modal/result.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_switch/flutter_switch.dart';
import 'package:shenfuhui/config/config.dart';
import 'package:shenfuhui/views/search_appbar.dart';

import '../routers/routers.dart';
import '../views/dialog_manager.dart';

///
/// 店铺主页的第二分页
///
class MallHomeProductsPage extends StatefulWidget {
  const MallHomeProductsPage({Key? key}) : super(key: key);

  @override
  State<MallHomeProductsPage> createState() => _MallHomeProductsPageState();
}

class _MallHomeProductsPageState extends State<MallHomeProductsPage> {
  var _menuIndex = 1;

  //返回商品列表item
  getListItem(int index) {
    return Container(
      height: 180.w,
      margin: EdgeInsets.symmetric(horizontal: 5.w, vertical: 0.w),
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(color: Config.colorDivider, width: 2.w),
        ),
      ),
      child: InkWell(
        onTap: () {
          Routes.navigateTo(context, Routes.productDetail,
              params: {'productId': '001'});
        },
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              margin: EdgeInsets.only(left: 20.w, right: 20.w),
              child: ClipRRect(
                borderRadius: BorderRadius.circular(5),
                child: Image.network(
                  "https://pic1.zhimg.com/v2-6438843a4cbae9184b935a75a5059ac6_1440w.jpg?source=172ae18b",
                  fit: BoxFit.fill,
                  width: 140.w,
                  height: 140.w,
                ),
              ),
            ),
            Container(
              height: 140.w,
              width: 480.w,
              child: Stack(
                children: [
                  Text(
                    "商品名称商品名称",
                    softWrap: true,
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                    style:
                        TextStyle(color: (Config.colorText1), fontSize: 22.w),
                  ),
                  Positioned(
                    bottom: 32.w,
                    child: Text(
                      "已售 999",
                      style:
                          TextStyle(fontSize: 20.sp, color: Config.colorText1),
                    ),
                  ),
                  Positioned(
                    bottom: 0.w,
                    child: Text(
                      "￥0.00",
                      style: TextStyle(fontSize: 20.sp, color: Colors.red),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Config.colorBg2,
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: BoxDecoration(
          color: Config.colorWhite,
          borderRadius: BorderRadius.circular(12.w),
        ),
        child: Stack(
          children: [
            Container(
              height: 80.w,
              decoration: BoxDecoration(
                border: Border(
                  bottom: BorderSide(color: Config.colorDivider, width: 2.w),
                ),
              ),
              width: double.infinity,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  InkWell(
                    onTap: () {
                      setState(() {
                        _menuIndex = 1;
                      });
                    },
                    child: Text(
                      '综合',
                      style: TextStyle(
                          fontSize: 25.sp,
                          color: _menuIndex == 1
                              ? Config.colorMain
                              : Config.colorText1),
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      setState(() {
                        _menuIndex = 2;
                      });
                    },
                    child: Text(
                      '销量',
                      style: TextStyle(
                          fontSize: 25.sp,
                          color: _menuIndex == 2
                              ? Config.colorMain
                              : Config.colorText1),
                    ),
                  ),
                  Row(
                    children: [
                      InkWell(
                        onTap: () {
                          setState(() {
                            _menuIndex = 3;
                          });
                        },
                        child: Text(
                          '价格',
                          style: TextStyle(
                              fontSize: 25.sp,
                              color: _menuIndex == 3
                                  ? Config.colorMain
                                  : Config.colorText1),
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
            Container(
              height: double.infinity,
              width: double.infinity,
              margin: EdgeInsets.only(top: 80.w),
              child: EasyRefresh(
                header: const MaterialHeader(),
                footer: const MaterialFooter(),
                onRefresh: () async {
                  await Future.delayed(const Duration(seconds: 1), () {
                    print('refresh');
                  });
                },
                onLoad: () async {
                  await Future.delayed(const Duration(seconds: 1), () {
                    print('load');
                  });
                },
                child: ListView.builder(
                  itemCount: 10,
                  // shrinkWrap: true,
                  // scrollDirection: Axis.vertical,
                  // physics: const BouncingScrollPhysics(),
                  itemBuilder: (BuildContext context, int index) {
                    return getListItem(index);
                  },
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
